'''
https://leetcode.cn/problems/meeting-rooms/description
https://leetcode.cn/problems/meeting-rooms-ii
'''
import heapq
from typing import List


class Solution:
    def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
        intervals.sort(key=lambda x: x[0])

        last_final_time = -1
        for start, end in intervals:
            if start < last_final_time:
                return False
            last_final_time = end
        return True

    def minMeetingRooms(self, intervals: List[List[int]]) -> int:
        intervals.sort(key=lambda x: x[0])
        pq = [-1]

        for start, end in intervals:
            if start >= pq[0]:
                heapq.heappop(pq)
            heapq.heappush(pq, end)
        return len(pq)

